package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.MallBill;
import com.sc.nft.entity.MallMemberEquity;
import com.sc.nft.entity.MallMemberEquityTarget;
import com.sc.nft.entity.dto.CheckHasPreemptionGetByTargetDTO;
import com.sc.nft.enums.MallBillStatusEnum;
import com.sc.nft.mapper.MallMemberEquityTargetMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：MallMemberEquityTargetDao
 * @Date：2024/4/2 19:29
 * @Filename：MallMemberEquityTargetDao
 */
@Slf4j
@Repository
public class MallMemberEquityTargetDao extends ServiceImpl<MallMemberEquityTargetMapper, MallMemberEquityTarget> {


    /**
     * 通过会员权益id获取
     *
     * @param mallMemberEquityId 商城会员权益Id
     * @return
     */
    public List<MallMemberEquityTarget> getList(Long mallMemberEquityId) {
        LambdaQueryWrapper<MallMemberEquityTarget> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallMemberEquityTarget::getMallMemberEquityId, mallMemberEquityId);
        return list(wrapper);
    }

    public boolean updateNumAndCanUseNum(Long mallMemberEquityId, Long targetId, Integer num) {
        UpdateWrapper<MallMemberEquityTarget> wrapper = new UpdateWrapper<>();
        wrapper.eq("mall_member_equity_id", mallMemberEquityId);
        wrapper.eq("target_id", targetId);
        wrapper.set("num", num);
        wrapper.set("can_use_num", num);
        return update(new MallMemberEquityTarget(), wrapper);
    }

    public boolean remove(Long mallMemberEquityId) {
        LambdaQueryWrapper<MallMemberEquityTarget> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallMemberEquityTarget::getMallMemberEquityId, mallMemberEquityId);
        return remove(wrapper);
    }

    public boolean reduceCanUseNum(long mallMemberEquityTargetId, Integer count) {
        return baseMapper.reduceCanUseNum(mallMemberEquityTargetId, count);
    }

    public boolean addCanUseNum(Long mallMemberEquityTargetId, Integer count) {
        return baseMapper.addCanUseNum(mallMemberEquityTargetId, count);
    }

    public List<CheckHasPreemptionGetByTargetDTO> checkHasPreemptionGetByTargetId(Long activitySpecId) {
        return baseMapper.checkHasPreemptionGetByTargetId(activitySpecId);
    }
}
